const mongoose = require('mongoose')
const Blog = mongoose.model('blog')

class Validate {
  async createBlog(title, content, author, tags) {
    if(!title) return {status: 0, msg: '请输入标题！'}
    if(!content) return {status: 0, msg: '请输入内容！'}
    if(!author) return {status: 0, msg: '请输入作者！'}
    if(!tags || tags.length === 0) return {status: 0, msg: '请输入标签！'}
    let blog = await Blog.findOne({title})
    if(blog) return {status: 0, msg: '博文名已占用！'}
  } 
  async updateBlog(_id, title, content, author, tags) {
    if(!_id) return {status: 0, msg: '请求参数缺少文章id！'}
    if(!title) return {status: 0, msg: '请输入标题！'}
    if(!content) return {status: 0, msg: '请输入内容！'}
    if(!author) return {status: 0, msg: '请输入作者！'}
    if(!tags || tags.length === 0) return {status: 0, msg: '请输入标签！'}
  }    
}

module.exports = new Validate()